<template>
	<view class="bg-white" style="height: 100%;">
		<cu-custom :isFromOutside="isFromOutside" :isBack="true">
			<block slot="backText">{{isFromOutside?'首页':'返回'}}</block>
			<block slot="content">帖子详情</block>
		</cu-custom>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption">
			<view v-if="post&&post.title" class="padding flex justify-start align-center">
				<view v-if="post.audit_status == -1" class="padding-right-xs">
					<view class="cu-tag line-red sm">未通过</view>
				</view>
				<text :selectable="true" :user-select="true" class="text-xl text-bold text-black">{{post.title}}</text>
			</view>
			<view v-if="post&&hasContent" class="flex justify-between align-center padding-left padding-right"
				style="width: 100%;">
				<view class="flex align-center" style="width: 100%;">
					<view class=" padding-right-xs">
						<view @tap="jumpToUserProfile(post.author.user_id)" class="cu-avatar round"
							:style="'background-image:url('+post.author.avatar+')'">
							<image v-if="post.author.sex!==-1" class="sex-icon" :src="'../../static/images/setting/'+[post.author.sex==0?'female':'male']+'.png'"></image>
						</view>
					</view>
					<view class="flex justify-start align-start" style="flex-direction: column;width: 100%;">
						<view class="flex justify-between align-center" style="width: 100%;">
							<view class="flex justify-start align-center">
								<text @tap="jumpToUserProfile(post.author.user_id)"
									:class="'text-df text-grey '+[post.author.role!==null?'padding-right-xs':'']">{{post.author.nickname}}</text>
								<view v-if="post.author.role!==null" :class="'radius cu-tag sm bg-'+roleColor">
									{{post.author.role.name}}
								</view>
								<view v-if="post.author.group!==null"
									class="flex justify-start align-center padding-left-xs">
									<view
										:class="'radius cu-tag sm bg-'+[post.author.group.open_choose==1?'gray text-grey':'blue']">
										{{post.author.group.name}}
									</view>
								</view>
							</view>
						</view>
						<view style="height: 2upx;"></view>
						<text class="text-left text-sm text-gray">{{post.show_time}}</text>
					</view>
				</view>
				<view v-if="post.owner_id!==loginUser.user_id" style="min-width: 100upx;">
					<button @tap="attentionAuthor(true)" v-if="post.author_attention==0" style="min-width: 100upx;"
						class="cu-btn bg-red sm"><text class="cuIcon-add"></text><text>关注</text></button>
					<button @tap="attentionAuthor(false)" v-else style="min-width: 100upx;"
						class="cu-btn bg-gray sm"><text>已关注</text></button>
				</view>
			</view>
			<view class="padding flex justify-start align-start" style="flex-direction: column;">
				<view v-if="post&&post.topic" class="padding-bottom-xs">
					<view @tap="jumpTopicPostList" class="flex justify-start align-center round"
						style="background-color: #eff6fb;padding: 6upx 10upx;">
						<view class="padding-right-xs">
							<image src="../../static/images/setting/topic.png" style="width: 30upx;height: 30upx;">
							</image>
						</view>
						<text class="text-blue">{{post.topic.title}}</text>
					</view>
				</view>
				<text v-if="post&&post.is_rich_content==false" :user-select="true" class="text-black text-lg"
					style="line-height: 50upx;letter-spacing: 3upx;">
					{{post.content}}
				</text>
				<rich-content-display v-else-if="post&&post.is_rich_content" :dataList="post.rich_content"
					style="width: 100%;"></rich-content-display>
			</view>
			<view v-if="post && post.link && post.link.length>0 && post.is_rich_content==false" class="padding"
				style="width: 100%;">
				<view v-if="hasVideo" style="width: 100%;">
					<video :src="post.link" :autoplay="false" controls objectFit="cover" :style="videoStyle"></video>
				</view>
				<view v-else>
					<view class="padding radius flex justify-between bg-gray">
						<view>
							<text class="cuIcon-link text-blue padding-right-xs"></text>
							<text class="text-blue">
								{{post.link}}
							</text>
						</view>
						<text class="cuIcon-right text-grey"></text>
					</view>
				</view>
			</view>
			<view v-if="post && post.is_rich_content==false">
				<view v-for="(url,index) in post.image_list" :key="index" class="bg-white padding-left padding-right"
					style="width: 100%;">
					<image @tap="ViewImage"
						:data-url="url+'?imageView2/0/q/75'+[url.indexOf('icodefuture')!==-1?waterMark:'']"
						:data-list="post.image_list" style="width: 100%;" class="bg-gray"
						:src="url+'?imageView2/2/w/1000/h/1000/q/75'+[url.indexOf('icodefuture')!==-1?waterMark:'']"
						mode="widthFix">
					</image>
				</view>
			</view>
			<!-- 投票区域 -->
			<view v-if="post&&post.vote&&hasContent" class="padding">
				<view class="bg-gray radius shadow-blur flex align-start padding"
					style="flex-direction: column;width: 100%;">
					<view class="flex justify-between align-center" style="width: 100%;">
						<text class="text-df">投票区</text>
						<text class="text-sm text-gray">{{post.vote.total_user}}人已参与</text>
					</view>
					<text class="text-df text-orange padding-top">{{post.vote.title}}</text>
					<view style="width: 100%;">
						<view v-if="post.is_voted">
							<view v-for="(vItem,index) in post.vote.items" :key="index">
								<view class="flex align-start justify-start padding-top"
									style="flex-direction: column;">
									<text
										class="text-df text-black padding-right padding-bottom-xs">{{vItem.content}}</text>
									<view class="cu-progress radius" style="width: 90%; height:40upx;">
										<view class="bg-cyan" :style="'width:'+vItem.percent+';'">
											{{vItem.user_count>0?vItem.percent:''}}
										</view>
										<text class="padding-left-xs text-df text-grey">{{vItem.user_count}}票</text>
									</view>
								</view>
							</view>
						</view>
						<view v-else style="width: 100%;">
							<view v-for="(vItem,index) in post.vote.items" :key="index" style="width: 100%;">
								<view class="padding-top">
									<button @tap="voteAction(vItem,index)" class="cu-btn lines-cyan radius"
										style="width: 100%;"><text
											class="text-df text-left">{{vItem.content}}</text></button>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- #ifdef MP-WEIXIN -->
			<!-- 关联的小程序或者公众号 -->
			<view v-if="post&&hasContent&&post.mini_program!==null" class="padding bg-gray radius margin-sm">
				<view @tap="jumpToMiniProgram(post.mini_program)" class="radius shadow-blur bg-white">
					<view class="flex justify-between align-center solid-bottom">
						<view
							class="padding-left padding-right padding-top-sm padding-bottom-sm flex justify-start align-center">
							<image src="../../static/images/setting/mini-program.png"
								style="width: 40upx;height: 40upx;"></image>
							<text class="text-bold text-df padding-left-xs">{{post.mini_program.name}}</text>
						</view>
						<text class="text-gray text-sm padding-left-sm padding-right"
							style="min-width: 100upx;">关联的小程序</text>
					</view>
					<view
						class="flex justify-between align-center padding-left padding-right padding-top-sm padding-bottom-sm"
						style="width: 100%;height: 100%;">
						<view class="flex justify-start align-center" style="width: 100%;height: 100%;">
							<view style="width: 120upx;height: 120upx;">
								<image mode="aspectFill" class="radius bg-gray" :src="post.mini_program.icon"
									style="width: 120upx;height: 120upx;"></image>
							</view>
							<text class="text-grey padding-left-sm">{{post.mini_program.introduce}}</text>
						</view>
						<text class="text-gray cuIcon-right"></text>
					</view>
				</view>
			</view>
			<view v-if="post&&hasContent&&post.official_account!==null" class="padding bg-gray radius margin-sm">
				<view @tap="jumToOfficialAccount(post.official_account)" class="radius shadow-blur bg-white">
					<view class="flex justify-between align-center solid-bottom">
						<view
							class="padding-left padding-right padding-top-sm padding-bottom-sm flex justify-start align-center">
							<image src="../../static/images/setting/official.png" style="width: 40upx;height: 40upx;">
							</image>
							<text class="text-bold text-df padding-left-xs">{{post.official_account.name}}</text>
						</view>
						<text class="text-gray text-sm padding-left-sm padding-right">关联的公众号</text>
					</view>
					<view
						class="flex justify-between align-center padding-left padding-right padding-top-sm padding-bottom-sm"
						style="width: 100%;height: 100%;">
						<view class="flex justify-start align-center" style="width: 100%;height: 100%;">
							<view style="width: 120upx;height: 120upx;">
								<image mode="aspectFill" class="radius bg-gray" :src="post.official_account.icon"
									style="width: 120upx;height: 120upx;"></image>
							</view>
							<text class="text-grey padding-left-sm">{{post.official_account.introduce}}</text>
						</view>
						<text class="text-gray cuIcon-right"></text>
					</view>
				</view>
			</view>
			<!-- #endif -->
			<!-- 推广商品 -->
			<view v-if="post&&hasContent&&post.mall_goods!==null&&post.mall_goods_buy_info!==null"
				class="padding bg-gray radius margin-sm">
				<goods-item-detail @click="jumpToBuyGoods" :mallType="post.mall_type" :goodsInfo="post.mall_goods">
				</goods-item-detail>
			</view>
			<!-- 订阅券 -->
			<view v-if="post&&hasContent&&post.forum_voucher!== null" class="padding bg-orange radius margin-sm">
				<forum-voucher-detail :finishGet="post.finish_get_policy==1" @getNow="getForumSubscribeSn(false)"
					@click="getForumSubscribeSn(true)" :voucher="post.forum_voucher"></forum-voucher-detail>
			</view>
			<!-- #ifdef MP-WEIXIN -->
			<!-- 代金券 -->
			<view v-if="post&&hasContent&&post.voucher_policy!== null" class="padding bg-orange radius margin-sm">
				<voucher-policy-detail :finishGet="post.finish_get_voucher==1" @getNow="getVoucherPolicySn(false)"
					@click="getVoucherPolicySn(true)" :policy="post.voucher_policy"></voucher-policy-detail>
			</view>
			<!-- #endif -->
			<!-- 腾讯文档 -->
			<view v-if="post&&post.document_list&&post.document_list.length>0" class="padding bg-gray radius margin-sm">
				<view v-for="(item,index) in post.document_list" :key="index">
					<detail-document @click="jumpToTencentDocument(item)" :document="item"></detail-document>
				</view>
			</view>
			<!-- 浏览数 -->
			<view v-if="post&&hasContent" class="flex justify-between align-center padding" style="width: 100%;">
				<view class="flex justify-start align-center padding-right-sm">
					<view class="cu-tag bg-gray text-grey">{{post.read_count}}次浏览</view>
					<view style="width: 20upx;"></view>
					<view @tap="jumpToForumDetail" v-if="post && post.forum"
						class="cu-tag bg-gray text-grey">{{post.forum.name}}</view>
				</view>
				<view v-if="isManager" class="action" @tap="lockPostAction">
					<button class="bg-gray sm cu-btn radius">
						<text class="cuIcon-lock text-grey"></text>
					</button>
				</view>
				<view v-else class="action" @tap="reportPostAction">
					<button class="bg-gray sm cu-btn radius">
						<text class="cuIcon-warn text-grey"></text>
					</button>
				</view>
			</view>
			<!-- 积分打赏 -->
			<view v-if="post" class="flex justify-start align-center padding-left padding-right" style="width: 100%;flex-direction: column;">
				<view class="flex justify-center align-center solid-bottom padding-bottom-sm" style="width: 100%;">
					<view style="width: 120upx;height: 120upx;">
						<image @tap="rewardAction" src="../../static/images/setting/reward.png" style="width: 100%;height: 100%;"></image>
					</view>
				</view>
				<view class="flex justify-start align-center padding-top-sm" style="flex-wrap: wrap;">
					<view v-for="(item,index) in post.reward_user_list" :key="index" style="width: 50upx;height: 50upx;margin-right: 20upx;">
						<image @tap="jumpToUserProfile(item.user_id)" class="bg-gray radius" :src="item.avatar" style="width: 100%;height: 100%;"></image>
					</view>
				</view>
				<view v-if="post.reward_user_count>0" class="flex justify-center align-center padding-top-sm" style="width: 100%;">
					<text class="text-gray text-sm">共{{post.reward_user_count}}人打赏了{{post.reward_score}}个山竹</text>
				</view>
			</view>
			<!-- 分享区域 -->
			<view v-if="post&&hasContent" class="flex align-center justify-around bg-white padding-bottom padding-top">
				<button @tap="favoriteAction"
					:class="'cuIcon-favor round '+['lines-'+(post.is_favorite?'orange':'gray')]"
					style="min-width: 200upx;"><text class="padding-left-xs">{{post.favorite_count}}</text></button>
				<button @tap="praisePostAction"
					:class="'round '+[post.is_praise?'text-red cuIcon-appreciatefill':'lines-gray cuIcon-appreciate']"
					style="min-width: 200upx;"><text class="padding-left-xs">{{post.praise_count}}</text></button>
				<button :disabled="canShare==false" open-type="share" class="lines-blue cuIcon-share round"
					style="min-width: 200upx;"><text class="padding-left-xs">{{post.forward_count}}</text></button>
			</view>
			<!-- 推荐数据 -->
			<view v-if="post.recommend">
				<feeds-recommend-user @attention="recommendUserAttention" v-if="post.recommend.user_list.length>0" :userList="post.recommend.user_list"></feeds-recommend-user>
				<feeds-recommend-circle v-if="post.recommend.circle_list.length>0" :dataList="post.recommend.circle_list"></feeds-recommend-circle>
				<feeds-recommend-circle-topic v-if="post.recommend.topic_list.length>0" :dataList="post.recommend.topic_list"></feeds-recommend-circle-topic>
			</view>
			<!-- 热门评论部分 -->
			<view v-if="post&&hasContent&&hotList.length>0">
				<!-- #ifndef MP-BAIDU -->
				<tui-sticky stickyHeight="104rpx" container>
					<template v-slot:header>
						<!-- #endif -->
						<view class="padding-left padding-top-sm padding-bottom-sm">
							<text class="cuIcon-hot text-red padding-right-xs"></text>
							<text class="text-df text-grey">热门评论 ({{hotList.length}})</text>
						</view>
						<!-- #ifndef MP-BAIDU -->
					</template>
					<template v-slot:content style="width: 100%;">
						<!-- #endif -->
						<view v-for="(comment,index) in hotList" :key="index" class="bg-white" style="width: 100%;">
							<comment-item :isHot="true" :index="index" @replyPraise="replyPraiseAction"
								@expandImageAction="expandImage(index,true)" @expandAction="expandComment(index,true)"
								@lock="commentLockAction(comment,index,true)"
								@detailParent=jumpCommentDetail(comment.parent_comment) :comment="comment"
								@detail="jumpCommentDetail(comment)" @report="reportCommentAction(comment)"
								@reply="replyCommentAction(comment)" @praise="praiseAction(comment,index)">
							</comment-item>
						</view>
						<!-- #ifndef MP-BAIDU -->
					</template>
				</tui-sticky>
				<!-- #endif -->
			</view>
			<!-- 全部评论部分 -->
			<view v-if="post&&hasContent">
				<!-- #ifndef MP-BAIDU -->
				<tui-sticky stickyHeight="104rpx" container>
					<template v-slot:header>
						<!-- #endif -->
						<view class="flex justify-between align-center padding-right">
							<view class="padding-left padding-top-sm padding-bottom-sm">
								<text class="cuIcon-comment text-grey padding-right-xs"></text>
								<text class="text-df text-grey">全部评论 ({{post.comment_count}})</text>
							</view>
							<view class="action" @tap="sortMenu.showActionSheet=true">
								<text class="cuIcon-sort"></text>
								<text class="text-gray text-sm">{{sortTypeLabel}}</text>
							</view>
						</view>
						<!-- #ifndef MP-BAIDU -->
					</template>
					<template v-slot:content style="width: 100%;">
						<!-- #endif -->
						<view v-for="(comment,index) in dataList" :key="index" class="bg-white" style="width: 100%;">
							<comment-item :isHot="false" :index="index" @replyPraise="replyPraiseAction"
								@expandImageAction="expandImage(index,false)" @expandAction="expandComment(index,false)"
								@lock="commentLockAction(comment,index,false)"
								@detailParent=jumpCommentDetail(comment.parent_comment) :comment="comment"
								@detail="jumpCommentDetail(comment)" @report="reportCommentAction(comment)"
								@reply="replyCommentActionNew(index,comment)" @praise="praiseAction(comment,index)">
							</comment-item>
						</view>
						<!-- #ifndef MP-BAIDU -->
					</template>
				</tui-sticky>
				<!-- #endif -->
			</view>
		</mescroll-body>
		<view class="cu-tabbar-height"></view>
		<view v-if="post&&hasContent" class="cu-bar foot bg-white">
			<view class="tui-operation">
				<view class="tui-operation-left tui-col-10 tui-height-full tui-ptop-zero">
					<view @click="sendCommentAction" class="tui-btn-comment">说说你的看法~</view>
				</view>
				<view class="padding-right tui-flex tui-align-center tui-operation-right tui-col-4">
					<view @tap="favoriteAction" class="padding-right-xl tui-operation-item action"
						hover-class="tui-opcity" :hover-stay-time="150">
						<tui-icon name="star" :size="18" :color="post.is_favorite?'#f37b1d':'#aaaaaa'"></tui-icon>
					</view>
					<view @tap="praisePostAction" class="padding-right tui-operation-item action"
						hover-class="tui-opcity" :hover-stay-time="150">
						<tui-icon :name="post.is_praise?'agree-fill':'agree'" :size="18"
							:color="post.is_praise?'#e54d42':'#aaaaaa'"></tui-icon>
					</view>
					<button open-type="share" class="padding-right bg-white">
						<view class="tui-operation-item" hover-class="tui-opcity" :hover-stay-time="150">
							<tui-icon name="share" :size="18" color='#0081ff'></tui-icon>
						</view>
					</button>
				</view>
			</view>
		</view>
		<view class="cu-modal" :class="modalStatus">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">{{isReportMode?'举报':'回复'}}{{isReportPost?'帖子':'评论'}}</view>
					<view class="action" @tap="modalStatus=''">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl flex justify-start" style="flex-direction: column;">
					<view v-if="isReportPost==false">
						<view class="flex justify-start align-center padding-bottom">
							<text class="text-grey text-sm">#{{form.replyUser}} : {{form.replyCommentContent}}</text>
						</view>
					</view>
					<view class="flex justify-center align-center padding-bottom-lg" style="width: 100%;">
						<textarea v-if="modalStatus.length > 0"
							class="bg-white radius padding-top padding-left text-left" v-model="form.textInput"
							placeholder="请输入内容"></textarea>
					</view>
					<view class="action flex justify-center padding bg-white" style="width: 100%;">
						<button @tap="commitOperate" class="cu-btn round bg-blue" style="width: 90%;">提交</button>
					</view>
				</view>
			</view>
		</view>
		<score-pay :userInfo="loginUserInfo" :index="scorePostIndex" @chooseScore="chooseScoreAction" @hidden="showScorePay=false" v-if="showScorePay" ref="scorePay" class="input-panel"></score-pay>
		<input-panel @onReplySuccess="onReplySuccess" @onCommentSuccess="onCommentSuccess" :originInfo="inputPanelOriginInfo"  @blur="showInputPanel=false" title="写评论" doneBtn="发表" :autoFocus="true" v-if="showInputPanel" class="input-panel"></input-panel>
		<tui-actionsheet :show="sortMenu.showActionSheet" :tips="sortMenu.tips" :item-list="sortMenu.itemList"
			:mask-closable="sortMenu.maskClosable" :color="sortMenu.color" :size="sortMenu.size"
			:is-cancel="sortMenu.isCancel" @click="itemClick" @cancel="closeActionSheet"></tui-actionsheet>
	</view>
</template>

<script>
	import RichContentDisplay from '@/components/rich-content-display.vue';
	import ForumVoucherDetail from '@/components/forum-voucher-detail.vue';
	import CommentItem from '@/components/comment-item.vue';
	import GoodsItemDetail from '@/components/goods-item-detail.vue';
	import VoucherPolicyDetail from '@/components/voucher-policy-detail.vue';
	import DetailDocument from '@/components/detail-document.vue'
	import InputPanel from '@/components/input-panel.vue'
	import FeedsRecommendUser from '@/components/feeds-recommend-user.vue'
	import FeedsRecommendCircle from '@/components/feeds-recommend-circle.vue'
	import FeedsRecommendCircleTopic from '@/components/feeds-recommend-circle-topic.vue'
	import ScorePay from '@/components/score-pay.vue'
	import {
		getTimeDistance,
		getTagColorForRole,
		chunk
	} from '@/api/utils.js'
	import {
		postDetail,
		postCommentList,
		favoritePost,
		reportPost,
		reportComment,
		replyComment,
		praiseComment,
		postMarkRead,
		vote,
		voteDetail,
		lockPost,
		lockComment,
		markMiniProgramUsed,
		markOfficialAccountUsed,
		getUnlockForumSn,
		increaseForward,
		praise,
		createVoucher,
		attentionUser,
		rewardOther
	} from '@/api/api.js'
	import {
		markRead
	} from '@/api/statusCache.js'
	import {
		isLogin,
		getToken,
		getReportTipReadStatus,
		setReportTipFinishRead,
		getUserInfo,
		updateUserInfo
	} from '@/api/auth.js'
	import {
		checkLogin
	} from '@/js_sdk/checkLogin.js'
	import config from '@/api/config.js'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		components: {
			CommentItem,
			GoodsItemDetail,
			ForumVoucherDetail,
			VoucherPolicyDetail,
			DetailDocument,
			RichContentDisplay,
			InputPanel,
			FeedsRecommendCircle,
			FeedsRecommendCircleTopic,
			FeedsRecommendUser,
			ScorePay
		},
		mixins: [MescrollMixin],
		data() {
			return {
				loginUserInfo:getUserInfo(),
				scorePostIndex: -1,
				showScorePay: false,
				inputPanelOriginInfo:null,
				showInputPanel:false,
				waterMark: '',
				windowWidth: 0,
				windowHeight: 0,
				isFromOutside: false,
				sortMenu: {
					lastSortType: null,
					sortType: 1,
					showActionSheet: false,
					maskClosable: true,
					itemList: [{
						text: "最新发表",
						color: "#0081ff"
					}, {
						text: "最多回复",
						color: "#2B2B2B"
					}, {
						text: "最多点赞",
						color: "#2B2B2B"
					}, {
						text: "只看楼主",
						color: "#2B2B2B"
					}, {
						text: "最早发表",
						color: "#2B2B2B"
					}],
					color: "#9a9a9a",
					size: 26,
					isCancel: true
				},
				postId: null,
				modalStatus: '',
				isReportMode: false,
				isReportPost: false,
				form: {
					replyUser: '',
					replyCommentContent: '',
					replyCommentId: null,
					textInput: '',
				},
				hotList: [],
				dataList: [],
				upOption: {
					page: {
						size: 10 // 每页数据的数量,默认10
					},
					textNoMore: config.customNoMore,
					noMoreSize: 1, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '还没有评论，快来抢占沙发吧!'
					}
				},
				post: null,
				requestStatus: {
					isPraising: false,
					isFavoriting: false,
					isMarkingRead: false,
					isVoting: false
				},
			}
		},
		computed: {
			hasContent() {
				if (this.post == null) {
					return false
				}
				if (this.post.is_rich_content) {
					return this.post.rich_content.length > 0
				}
				return this.post.content && this.post.content.length > 0
			},
			loginUser() {
				return getUserInfo()
			},
			hasVideo() {
				return this.post && this.post.link && this.post.link.length > 0 && this.post.link.indexOf('.mp4') !== -1
			},
			videoSize() {
				if (this.hasVideo == false) {
					return null
				}
				if (!this.post || !this.post.link) {
					console.log('no link');
					return null
				}
				if (this.getCharCount(this.post.link, '_') !== 2) {
					console.log('no width info!');
					return null
				}
				let fileName = this.post.link.split('/').slice(-1)
				console.log(fileName);
				let namePart = String(fileName).split('.')[0]
				console.log(namePart);
				let nameArr = namePart.split('_')
				let vWidth = nameArr[1]
				let vHeight = nameArr[2]
				let vScale = vHeight / vWidth
				console.log('height:' + height);
				let gapScale = this.windowWidth / 320
				let width = this.windowWidth - (2 * 12 * gapScale)
				let height = width * vScale
				return {
					width: width,
					height: height
				}
			},
			videoStyle() {
				if (this.videoSize == null) {
					return 'width:100%;'
				}
				return 'width:' + this.videoSize.width + 'px;height:' + this.videoSize.height + 'px;'
			},
			isManager() {
				if (isLogin() == false) {
					return false
				}
				let userInfo = getUserInfo()
				if (userInfo.role == null) {
					return false
				}
				return userInfo.role_id > 0
			},
			roleColor() {
				if (this.post == null ||
					this.post.author == null ||
					this.post.author.role == null) {
					return 'white'
				}
				return getTagColorForRole(this.post.author.role.role_id)
			},
			canShare() {
				if (this.post == null) {
					return false
				}
				if (this.post.audit_status !== 1) {
					return false
				}
				return true
			},
			auditStatus() {
				if (this.post == null || this.post.auditStatus == 1) {
					return
				}
				let map = {
					'-1': {
						'color': 'red',
						'name': '未通过'
					},
					'0': {
						'color': 'cyan',
						'name': '审核中'
					}
				}
				return map[this.post.audit_status]
			},
			sortTypeLabel() {
				let map = {
					1: '最新发表',
					2: '最多回复',
					3: '最多点赞',
					4: '只看楼主',
					5: '最早发表'
				}
				return map[this.sortMenu.sortType]
			}
		},
		onLoad(options) {
			this.waterMark = config.waterMark
			let scene = uni.getStorageSync('AppLaunchFromTimeline')
			if (scene !== null && scene !== undefined && scene !== "") {
				this.isFromOutside = true
			}
			console.log(options)
			if (options.postId !== null && options.postId !== undefined && options.postId.length > 0) {
				this.postId = options.postId
				if (options.outside !== null && options.outside !== undefined) {
					this.isFromOutside = true
				}
			}
			let that = this
			uni.$on('PostNeedUpdateCommentList', function(data) {
				if (data.postId == that.postId) {
					if (that.mescroll) {
						that.mescroll.resetUpScroll()
					}
				}
			})
			uni.getSystemInfo({
				success(res) {
					that.windowWidth = res.windowWidth
					that.windowHeight = res.windowHeight
				}
			})
		},
		methods: {
			chooseScoreAction(params) {
				let score = params[0]
				let postId = this.post.post_id
				uni.showLoading({
					title: '正在提交...'
				})
				rewardOther(postId, score).then(res => {
					uni.hideLoading()
					uni.showToast({
						icon: 'none',
						title: '打赏成功'
					})
					this.showScorePay = false
					let newPayer = [this.loginUserInfo]
					if(this.post.reward_user_list&&this.post.reward_user_list.length>0) {
						let first = this.post.reward_user_list[0]
						if(first.user_id != this.loginUserInfo.user_id) {
							this.post.reward_user_list = newPayer.concat(this.post.reward_user_list)
							this.post.reward_user_count++
						}
					}else{
						this.post.reward_user_list = newPayer.concat(this.post.reward_user_list)
						this.post.reward_user_count++
					}
					this.post.reward_score += score
					updateUserInfo()
					let that = this
					setTimeout(() => {
						that.loginUserInfo = getUserInfo()
					}, 300)
				}).catch(error => {
			
				})
			},
			rewardAction() {
				if (isLogin() == false) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				let otherUserId = this.post.owner_id
				if (otherUserId == this.loginUserInfo.user_id) {
					uni.showToast({
						icon: 'none',
						title: '不要自己打赏自己哦~'
					})
					return
				}
				this.showScorePay = true
				this.scorePostIndex = 0
			},
			recommendUserAttention(passParams)
			{
				if (isLogin() == false) {
					let that = this
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				let listIndex = passParams[0]
				let subIndex = passParams[1]
				let item = this.post.recommend.user_list[subIndex]
				let status = item.is_attention==1? 0:1
				uni.showLoading({
					title: '正在提交...'
				})
				attentionUser(item.user_id,status).then(res => {
					uni.hideLoading()
					item.is_attention = status
					let tip = status == 1 ? '已关注' : '已取消'
					uni.showToast({
						title: tip
					})
				}).catch(error => {
					uni.hideLoading()
				})
			},
			onReplySuccess(params)
			{
				let commentIndex = params[0]
				let comment = params[1]
				let commentList = [comment]
				let parentComment = this.dataList[commentIndex]
				if(parentComment.reply_list&&parentComment.reply_list.length>0) {
					parentComment.reply_list = commentList.contact(parentComment.reply_list)
				}else{
					parentComment.reply_list = commentList
				}
			},
			onCommentSuccess(params) 
			{
				let postIndex = params[0]
				let comment = params[1]
				let commentList = [comment]
				this.dataList = commentList.concat(this.dataList)
			},
			replyCommentActionNew(index,comment) 
			{
				let post = this.post
				let info = {
					'postId':post.post_id,
					'commentId':comment.comment_id,
					'replyUser':comment.author.nickname,
					'postIndex':index
				}
				this.inputPanelOriginInfo = info
				this.showInputPanel = true
			},
			sendCommentAction()
			{
				if (isLogin() == false) {
					let that = this
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				let info = {
					'postId':this.post.post_id,
					'postIndex':0
				}
				this.inputPanelOriginInfo = info
				this.showInputPanel = true
			},
			getVideoStyle(url) {
				let videoSize = this.getVideoSize(url)
				if (videoSize == null) {
					return 'width:100%;'
				}
				return 'width:' + videoSize.width + 'px;height:' + videoSize.height + 'px;'
			},
			getVideoSize(url) {
				if (!url) {
					console.log('no link');
					return null
				}
				if (this.getCharCount(url, '_') !== 2) {
					console.log('no width info!');
					return null
				}
				let fileName = url.split('/').slice(-1)
				console.log(fileName);
				let namePart = String(fileName).split('.')[0]
				console.log(namePart);
				let nameArr = namePart.split('_')
				let vWidth = nameArr[1]
				let vHeight = nameArr[2]
				let vScale = vHeight / vWidth
				console.log('height:' + height);
				let gapScale = this.windowWidth / 320
				let width = this.windowWidth - (2 * 12 * gapScale)
				let height = width * vScale
				return {
					width: width,
					height: height
				}
			},
			getCharCount(str, char) {
				var regex = new RegExp(char, 'g'); // 使用g表示整个字符串都要匹配
				var result = str.match(regex); //match方法可在字符串内检索指定的值，或找到一个或多个正则表达式的匹配。
				var count = !result ? 0 : result.length;
				return count;
			},
			replyPraiseAction(passParams) {
				let index = passParams[0]
				let innerIndex = passParams[1]
				let isHot = passParams[2]
				let reply = null
				if (isHot) {
					reply = this.hotList[index].reply_list[innerIndex]
					if (reply.is_praise == 0) {
						this.hotList[index].reply_list[innerIndex].praise_count++
					} else {
						this.hotList[index].reply_list[innerIndex].praise_count--
					}
					this.hotList[index].reply_list[innerIndex].is_praise = !this.hotList[index].reply_list[innerIndex]
						.is_praise
				} else {
					reply = this.dataList[index].reply_list[innerIndex]
					if (reply.is_praise == 0) {
						this.dataList[index].reply_list[innerIndex].praise_count++
					} else {
						this.dataList[index].reply_list[innerIndex].praise_count--
					}
					this.dataList[index].reply_list[innerIndex].is_praise = !this.dataList[index].reply_list[innerIndex]
						.is_praise
				}
				if (reply !== null) {
					praiseComment(reply.comment_id).then(res => {

					}).catch(error => {

					})
				}
			},
			expandImage(index, isHot) {
				if (isHot) {
					this.hotList[index].is_image_expand = !this.hotList[index].is_image_expand
				} else {
					this.dataList[index].is_image_expand = !this.dataList[index].is_image_expand
				}
			},
			expandComment(index, isHot) {
				if (isHot) {
					this.hotList[index].is_expand = !this.hotList[index].is_expand
				} else {
					this.dataList[index].is_expand = !this.dataList[index].is_expand
				}
			},
			jumpToForumDetail() {
				uni.navigateTo({
					url: '/pages/lessuse/forum-post-list/forum-post-list?forumId=' + this.post.forum.forum_id +
						'&forumName=' + this.post.forum.name
				})
			},
			attentionAuthor(action) {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				let status = action == true ? 1 : 0
				this.post.author_attention = status
				attentionUser(this.post.owner_id, status).then(res => {
					console.log('attention success');
					let title = status == 1 ? '已关注!' : '已取消关注!'
					uni.showToast({
						icon: 'none',
						title: title
					})
				}).catch(error => {

				})
			},
			jumpToTencentDocument(item) {
				// #ifdef MP-WEIXIN
				let pagePath = 'pages/detail/detail?url=' + encodeURI(item.link)
				uni.navigateToMiniProgram({
					appId: 'wxd45c635d754dbf59',
					path: pagePath,
					success(res) {
						// 打开成功
						console.log('open mini success!');
					}
				})
				// #endif
				// #ifdef MP-QQ
				let pagePath = 'pages/detail/detail?url=' + encodeURI(item.link)
				uni.navigateToMiniProgram({
					appId: '1108338344',
					path: pagePath,
					success(res) {
						// 打开成功
						console.log('open mini success!');
					}
				})
				// #endif
			},
			jumpTopicPostList() {
				let that = this
				uni.navigateTo({
					url: '/pages/always/topic-post-list/topic-post-list?topicId=' + that.post.topic_id,
					success: function(res) {
						res.eventChannel.emit('topicPostList', that.post.topic)
					}
				})
			},
			praisePostAction() {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				let isPraise = this.post.is_praise
				praise(this.post.post_id).then(res => {
					this.post.is_praise = isPraise == 1 ? 0 : 1
					if (isPraise == 1) {
						this.post.praise_count -= 1
						uni.showToast({
							icon: 'none',
							title: '已取消点赞'
						})
					} else {
						this.post.praise_count += 1
						uni.showToast({
							icon: 'none',
							title: '已点赞'
						})
					}
				}).catch(error => {
					console.log('点赞数增长失败');
				})
			},
			getVoucherPolicySn(needTip) {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				if (this.post.finish_get_voucher) {
					return
				}
				if (needTip == false) {
					uni.showLoading({
						title: '拼命领取中...'
					})
					createVoucher(this.post.voucher_policy.policy_id).then(res => {
						uni.hideLoading()
						this.post.finish_get_voucher = 1
						uni.showToast({
							title: '领取成功!'
						})
					}).catch(error => {
						uni.hideLoading()
					})
				} else {
					let that = this
					uni.showModal({
						title: '领券提示',
						content: '是否需要立即领取该券',
						cancelText: '不需要',
						confirmText: '是的',
						success(res) {
							if (res.confirm) {
								uni.showLoading({
									title: '拼命领取中...'
								})
								createVoucher(that.post.voucher_policy.policy_id).then(res => {
									uni.hideLoading()
									that.post.finish_get_voucher = 1
									uni.showToast({
										title: '领取成功!'
									})
								}).catch(error => {
									uni.hideLoading()
								})
							}
						}
					})
				}
			},
			getForumSubscribeSn(needTip) {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				if (this.post.finish_get_policy) {
					return
				}
				if (needTip == false) {
					uni.showLoading({
						title: '拼命领取中...'
					})
					getUnlockForumSn(this.post.forum_voucher.forum_id, this.post.forum_voucher.policy_id).then(res => {
						uni.hideLoading()
						this.post.finish_get_policy = 1
						uni.showToast({
							title: '领取成功!'
						})
					}).catch(error => {
						uni.hideLoading()
					})
				} else {
					let that = this
					uni.showModal({
						title: '领券提示',
						content: '是否需要立即领取该券',
						cancelText: '不需要',
						confirmText: '是的',
						success(res) {
							if (res.confirm) {
								uni.showLoading({
									title: '拼命领取中...'
								})
								getUnlockForumSn(that.post.forum_voucher.forum_id, that.post.forum_voucher
									.policy_id).then(res => {
									uni.hideLoading()
									that.post.finish_get_policy = 1
									uni.showToast({
										title: '领取成功!'
									})
								}).catch(error => {
									uni.hideLoading()
								})
							}
						}
					})
				}
			},
			jumpToBuyGoods() {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				if (this.post && this.post.mall_type == 0 && this.post.mall_goods_buy_info) {
					// #ifdef MP-WEIXIN
					let appInfo = this.post.mall_goods_buy_info.we_app_info
					uni.navigateToMiniProgram({
						appId: appInfo.app_id,
						path: appInfo.page_path,
						success(res) {
							// 打开成功
							console.log('open mini success!');
						}
					})
					// #endif
					// #ifdef MP-QQ
					let appInfo = this.post.mall_goods_buy_info.qq_app_info
					uni.navigateToMiniProgram({
						appId: appInfo.app_id,
						path: appInfo.page_path,
						success(res) {
							// 打开成功
							console.log('open mini success!');
						}
					})
					// #endif
				}

				//自营商品
				if (this.post && this.post.mall_type == 1 && this.post.mall_goods) {
					if (isLogin() == false) {
						checkLogin()
						return
					}
					// #ifdef MP-WEIXIN
					uni.navigateTo({
						url: '/pages/always/create-order/create-order?shopId=' + this.post.mall_goods.shop_id
					})
					// #endif
					// #ifndef MP-WEIXIN
					uni.showModal({
						title: '该平台暂不支持橱窗购买!'
					})
					// #endif
				}
			},
			getCharCount(str, char) {
				var regex = new RegExp(char, 'g'); // 使用g表示整个字符串都要匹配
				var result = str.match(regex); //match方法可在字符串内检索指定的值，或找到一个或多个正则表达式的匹配。
				var count = !result ? 0 : result.length;
				return count;
			},
			jumToOfficialAccount(item) {
				uni.showModal({
					title: '平台提示',
					content: '暂不支持从小程序跳转公众号，是否需要复制公众号名称？',
					cancelText: '暂不需要',
					confirmText: '立即复制',
					success(res) {
						if (res.confirm) {
							uni.setClipboardData({
								data: item.name,
								success: function() {
									uni.showToast({
										icon: 'none',
										title: '已复制!'
									});
									markOfficialAccountUsed(item.account_id).then(res => {
										console.log('标记公众号使用成功:' + item.account_id);
									}).catch(error => {
										console.log('标记公众号使用失败:' + item.account_id)
									})
								}
							});
						}
					}
				})
			},
			jumpToMiniProgram(item) {
				uni.navigateToMiniProgram({
					appId: item.app_id,
					path: 'pages/index/index',
					success(res) {
						// 打开成功
						console.log('open mini success!');
					}
				})
				markMiniProgramUsed(item.program_id).then(res => {
					console.log('标记小程序使用记录成功:' + item.program_id);
				}).catch(error => {
					console.log('标记小程序使用记录失败:' + item.program_id);
				})
			},
			commentLockAction(comment, index, isHot) {
				let that = this
				uni.showModal({
					title: '审核评论提示',
					content: '是否确定要将评论击飞??',
					cancelText: '手滑了',
					confirmText: '击飞评论',
					success(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '正在操作...'
							})
							lockComment(comment.comment_id).then(res => {
								uni.hideLoading()
								uni.showToast({
									title: '操作成功'
								})
								if (isHot) {
									that.hotList[index].audit_status = -1
								} else {
									that.dataList[index].audit_status = -1
								}
							}).catch(error => {
								uni.hideLoading()
								uni.showToast({
									icon: 'none',
									title: '操作失败'
								})
							})
						}
					}
				})
			},
			lockPostAction() {
				let that = this
				uni.showModal({
					title: '审核帖子提示',
					content: '是否要将帖子打回成未审核通过，打回后帖子将不会在信息流出现也不可分享给他人',
					cancelText: '手滑了',
					confirmText: '打回帖子',
					success(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '正在操作...'
							})
							lockPost(that.post.post_id).then(res => {
								uni.hideLoading()
								uni.showToast({
									title: '操作成功'
								})
								that.downCallback()
							}).catch(error => {
								uni.hideLoading()
								uni.showToast({
									icon: 'none',
									title: '操作失败'
								})
							})
						}
					}
				})
			},
			jumpToUserProfile(userId) {
				uni.navigateTo({
					url: '/pages/profile/profile?userId=' + userId
				})
			},
			voteAction(voteItem, index) {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				if (this.requestStatus.isVoting) {
					return
				}
				this.requestStatus.isVoting = true
				vote(this.postId, voteItem.vote_item_id, voteItem.vote_id).then(res => {
					this.requestStatus.isVoting = false
					this.post.is_voted = true
					this.post.vote.total_user += 1
					this.post.vote.items[index].user_count += 1
					this.post.vote.items.forEach(item => {
						let percent = ((item.user_count / this.post.vote.total_user).toFixed(2) * 100)
						console.log('vote item percent:' + String(percent))
						item['percent'] = String(percent) + '%'
					})
				}).catch(error => {
					this.requestStatus.isVoting = false
				})
			},
			onShareAppMessage(res) {
				if (!this.canShare) {
					return {
						title: '帖子内容未获取或未通过审核,暂不可分享',
						path: '/pages/detail/detail?postId=0&outside=1'
					}
				}
				if (res.from === 'button') { // 来自页面内分享按钮
					console.log(res.target)
				}
				increaseForward(this.post.post_id).then(res => {
					console.log('转发数增长成功');
				}).catch(error => {
					console.log('转发数增长失败');
				})
				return {
					title: this.post.title,
					path: '/pages/detail/detail?postId=' + this.post.post_id + '&outside=1'
				}
			},
			onShareTimeline(res) {
				if (!this.canShare) {
					return {
						title: '帖子内容未获取或未通过审核,暂不可分享',
						path: '/pages/detail/detail?postId=0&outside=1'
					}
				}
				increaseForward(this.post.post_id).then(res => {
					console.log('转发数增长成功');
				}).catch(error => {
					console.log('转发数增长失败');
				})
				return {
					title: this.post.title,
					path: '/pages/detail/detail?postId=' + this.post.post_id + '&outside=1'
				}
			},
			favoriteAction() {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				if (this.requestStatus.isFavoriting) {
					return
				}
				this.requestStatus.isFavoriting = true
				uni.showLoading({
					title: '正在提交...'
				})
				favoritePost(this.postId).then(res => {
					this.requestStatus.isFavoriting = false
					uni.hideLoading()
					if (this.post.is_favorite) {
						this.post.favorite_count -= 1
						this.post.is_favorite = 0
						uni.showToast({
							icon: 'none',
							title: '已取消收藏'
						})
					} else {
						this.post.favorite_count += 1
						this.post.is_favorite = 1
						uni.showToast({
							title: '收藏成功'
						})
					}
				}).catch(error => {
					this.requestStatus.isFavoriting = false
					uni.hideLoading()
					uni.showToast({
						icon: 'none',
						title: '收藏失败!'
					})
				})
			},
			commitOperate() {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				this.modalStatus = null
				uni.showLoading({
					title: '正在提交...'
				})
				if (this.isReportMode) {
					if (this.isReportPost) {
						reportPost(this.postId, this.form.textInput).then(res => {
							uni.hideLoading()
							uni.showToast({
								title: '举报已提交'
							})
						}).catch(error => {
							uni.hideLoading()
							uni.showToast({
								icon: 'none',
								title: '提交失败'
							})
						})
					} else {
						reportComment(this.form.replyCommentId, this.form.textInput).then(res => {
							uni.hideLoading()
							uni.showToast({
								title: '举报已提交'
							})
						}).catch(error => {
							uni.hideLoading()
							uni.showToast({
								icon: 'none',
								title: '提交失败'
							})
						})
					}
				} else {
					replyComment(this.form.replyCommentId, this.form.textInput).then(res => {
						uni.hideLoading()
						uni.showToast({
							title: '回复成功'
						})
						this.dataList.unshift(res.data)
					}).catch(error => {
						uni.hideLoading()
						uni.showToast({
							icon: 'none',
							title: '提交失败'
						})
					})
				}
			},
			praiseAction(comment, index) {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				if (this.requestStatus.isPraising) {
					return
				}
				this.requestStatus.isPraising = true
				praiseComment(comment.comment_id).then(res => {
					if (comment.is_praise == 0) {
						if (comment.is_hot) {
							this.hotList[index].is_praise = 1
							this.hotList[index].praise_count += 1
						} else {
							this.dataList[index].is_praise = 1
							this.dataList[index].praise_count += 1
						}
						uni.showToast({
							title: '点赞成功'
						})
						this.requestStatus.isPraising = false
					} else {
						if (comment.is_hot) {
							this.hotList[index].is_praise = 0
							this.hotList[index].praise_count -= 1
						} else {
							this.dataList[index].is_praise = 0
							this.dataList[index].praise_count -= 1
						}
						uni.showToast({
							icon: 'none',
							title: '已取消点赞'
						})
						this.requestStatus.isPraising = false
					}
				}).catch(error => {
					console.log(error)
					uni.showToast({
						icon: 'none',
						title: '提交失败'
					})
					this.requestStatus.isPraising = false
				})
			},
			getPostDetail() {
				//通过postId拉取
				uni.showLoading({
					title: '正在加载...'
				})
				postDetail(this.postId).then(res => {
					this.post = res.data
					this.post.show_time = getTimeDistance(res.data.created_at)
					if (res.data.rich_content && res.data.rich_content.length > 0) {
						this.post.rich_content = JSON.parse(res.data.rich_content)
						this.post.is_rich_content = true
						if(this.post.has_video==1) {
							this.post.rich_content.forEach(item=>{
								if(item.type=='video') {
									item.videoStyle = this.getVideoStyle(item.url)
								}
							})
						}
					} else {
						this.post.is_rich_content = false
					}
					if (this.post.vote && this.post.vote.total_user > 0) {
						this.post.vote.items.forEach(item => {
							let percent = ((item.user_count / this.post.vote.total_user) * 100).toFixed(2)
							console.log('vote item percent:' + String(percent))
							item['percent'] = String(percent) + '%'
						})
					}
					uni.hideLoading()
					if (res.data.is_read == 0) {
						let token = getToken()
						if (token !== null && token !== undefined && this.requestStatus.isMarkingRead == false) {
							this.requestStatus.isMarkingRead = true
							postMarkRead(this.postId).then(res => {
								console.log(this.postId + '帖子标记已读成功')
								this.requestStatus.isMarkingRead = false
							}).catch(error => {
								console.log(this.postId + '帖子标记已读失败')
								this.requestStatus.isMarkingRead = false
							})
						}
					} else {
						console.log("帖子已经是已读状态")
					}
				}).catch(error => {
					uni.hideLoading()
					let that = this
					if (isLogin() == false) {
						if (error.code == 30021) {
							uni.showModal({
								title: '订阅权限提示',
								content: '本帖内容为付费版块内容，需要付费才可查看，是否立即登录同步权限?',
								confirmText: '立即登录',
								success(res) {
									if (res.confirm) {
										uni.navigateTo({
											url: '/pages/login/login',
											events: {
												loginSuccess: function(data) {
													that.getPostDetail()
												}
											}
										})
									}
								}
							})
						} else if (error.code == 30022) {
							uni.showModal({
								title: '订阅权限提示',
								content: '本帖内容为授权版块内容，需要授权才可查看，是否立即登录同步权限?',
								confirmText: '立即登录',
								success(res) {
									if (res.confirm) {
										uni.navigateTo({
											url: '/pages/login/login',
											events: {
												loginSuccess: function(data) {
													that.getPostDetail()
												}
											}
										})
									}
								}
							})
						}
					} else {
						if (error.code == 30021) {
							this.post = error.data
							let content = '本帖内容为付费版块《' + this.post.forum.name + '》的内容，需要付费才可查看，是否前往橱窗购买??'
							uni.showModal({
								title: '订阅权限提示',
								content: content,
								confirmText: '前往购买',
								success(res) {
									if (res.confirm) {
										uni.navigateTo({
											url: '/pages/always/create-order/create-order?shopId=1'
										})
									}
								}
							})
						} else if (error.code == 30022) {
							this.post = error.data
							let content = '本帖内容为授权版块《' + this.post.forum.name + '》的内容，需要授权才可查看，是否前往《我领的券》使用订阅券授权?'
							uni.showModal({
								title: '订阅权限提示',
								content: content,
								confirmText: '前往授权',
								success(res) {
									if (res.confirm) {
										uni.navigateTo({
											url: '/pages/always/subscribe-voucher-list/subscribe-voucher-list'
										})
									}
								}
							})
						}
					}
				})
			},
			closeActionSheet: function() {
				this.sortMenu.showActionSheet = false
			},
			itemClick: function(e) {
				let sortType = e.index + 1
				this.sortMenu.lastSortType = this.sortMenu.sortType;
				this.sortMenu.sortType = sortType;
				this.sortMenu.itemList[e.index].color = '#0081ff'
				this.sortMenu.itemList[this.sortMenu.lastSortType - 1].color = '#2B2B2B'
				if (this.mescroll) {
					this.mescroll.resetUpScroll()
				}
				this.closeActionSheet();
			},
			jumpProfileAction() {
				uni.navigateTo({
					url: '/pages/profile/profile'
				})
			},
			jumpCommentDetail(comment) {
				uni.navigateTo({
					url: '/pages/always/comment-detail/comment-detail?commentId=' + comment.comment_id
				})
			},
			commentAction() {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				uni.navigateTo({
					url: '/pages/comment/comment?postId=' + this.post.post_id
				})
			},
			replyCommentAction(comment) {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				uni.navigateTo({
					url: '/pages/comment/comment?postId=' + comment.post_id,
					success: function(res) {
						// 通过eventChannel向被打开页面传送数据
						res.eventChannel.emit('replyComment', comment)
					}
				})
			},
			reportCommentAction(comment) {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				this.form.replyCommentId = comment.comment_id
				this.form.replyUser = comment.author.nickname
				this.form.replyCommentContent = comment.content
				this.isReportPost = false
				this.isReportMode = true
				this.modalStatus = 'show'
			},
			reportPostAction() {
				if (isLogin() == false) {
					checkLogin()
					return
				}
				let status = getReportTipReadStatus()
				if (status === false) {
					let that = this
					uni.showModal({
						title: '平台提示',
						content: '请如实根据当前需举报内容的真实性进行举报，如果多次举报被判定无效举报或者恶意举报将会被平台永久拉黑!',
						confirmText: '知道了',
						cancelText: '手滑了',
						success(res) {
							if (res.confirm) {
								that.isReportPost = true
								that.isReportMode = true
								that.modalStatus = 'show'
							}
						},
						complete() {
							setReportTipFinishRead()
						}
					})
				} else {
					this.isReportPost = true
					this.isReportMode = true
					this.modalStatus = 'show'
				}
			},
			getDataList(pageIndex, pageSize) {
				postCommentList(this.postId, pageIndex, pageSize, this.sortMenu.sortType).then(res => {
					if (pageIndex == 0) {
						res.data.hot_list.forEach(item => {
							item.show_time = getTimeDistance(item.created_at)
							item.is_expand = false
							item.is_image_expand = true
						})
					}
					let pageList = res.data.list
					pageList.forEach(item => {
						item.show_time = getTimeDistance(item.created_at)
						item.is_expand = false
						item.is_image_expand = true
					})
					if (pageIndex == 0) {
						this.hotList = res.data.hot_list
					}
					if (pageIndex == 0) {
						this.dataList = pageList
					} else {
						this.dataList = this.dataList.concat(pageList)
					}
					this.post.comment_count = res.data.total
					let hasNext = pageList.length >= pageSize
					if (this.mescroll) {
						this.mescroll.endSuccess(this.dataList.length, hasNext);
					}
				}).catch(error => {
					if (this.mescroll) {
						this.mescroll.endErr()
					}
				})
			},
			downCallback() {
				this.getPostDetail()
				if (this.mescroll) {
					this.mescroll.resetUpScroll()
				}
			},
			upCallback(page) {
				let pageIndex = page.num - 1
				this.getDataList(pageIndex, page.size)
			},
			ViewImage(e) {
				console.log(e.currentTarget.dataset.list)
				console.log(e.currentTarget.dataset.url)
				let fixList = []
				e.currentTarget.dataset.list.forEach(item => {
					fixList.push(item + '?imageView2/0/q/75' + [item.indexOf('icodefuture') !== -1 ? this
						.waterMark : ''
					])
				})
				uni.previewImage({
					urls: fixList,
					current: e.currentTarget.dataset.url,
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			}
		}
	}
</script>

<style scoped>
	@import '@/static/style/thorui.css';

	.container {
		padding: 30rpx 0 80rpx 0;
		box-sizing: border-box;
		overflow: hidden;
	}

	.tui-padding {
		padding: 0 30rpx;
		box-sizing: border-box;
		overflow: hidden;
	}

	.tui-title {
		padding: 55rpx 0 30rpx 0;
		font-size: 32rpx;
		color: #333;
		font-weight: bold
	}

	.tui-flex {
		align-items: center;
	}

	.tui-triangle {
		margin-right: 30rpx;
	}

	.tui-checkbox {
		margin-left: 60rpx;
	}

	.tui-top40 {
		margin-top: 40rpx;
	}

	.tui-pl-30 {
		padding-left: 30rpx;
	}
	
	.input-panel {
		position: fixed;
		height: 100%;
		width: 100%;
		bottom: 0%;
		z-index: 9999;
	}
	.sex-icon {
		z-index: 10;
		position: absolute;
		bottom: -3px;
		width: 20upx;
		height: 20upx;
	}
</style>
